package com.zhxh.nzpos.api;

import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;

import com.zhxh.nzpos.api.exception.AuthenticationException;
import com.zhxh.nzpos.api.exception.AuthorizationException;
import com.zhxh.nzpos.api.exception.CommunicationException;

/**
 * PosInit Pos终端初始化
 * Pos 机首次访问服务器,分配 pos 机 ID
 * 
 * @author wangzt
 *
 */
public class ConnectorPosID {
	private KSoapExecutor soap;
	
	public ConnectorPosID() {
		soap = new KSoapExecutor();
	}
	
	public String getPosID(String cardId) throws CommunicationException,
			AuthorizationException, AuthenticationException {

		SoapObject getPosID = SoapObjectBuilder.start()
				.withMethod("PosInit")
				.withProperty("Key", SoapObjectBuilder.KEY)
				.withProperty("CardID", cardId)
				.build();

		SoapPrimitive vc = null;
		try {
			vc = (SoapPrimitive)soap.execute(getPosID);
			System.out.println("posID#####################vc=" + vc);
		} catch (org.apache.http.auth.AuthenticationException e) {
			e.printStackTrace();
		}
		if (vc == null)
			return null;

		String posID = vc.toString();
		
		return posID;
	}
}
